// deepClone深拷贝  注意 基本数据类型和引用数据类型

function deepClone(source) {
    let target, sourceType = Object.prototype.toString.call(source).slice(8, -1).toLowerCase();

    if (sourceType === 'object') {
        target = {};
    } else if (sourceType === 'array') {
        target = [];
    } else {
        return source;
    };

    // 这里要用for in 
    for (let i in source) {
        let temp = source[i], tempType = Object.prototype.toString.call(temp).slice(8, -1).toLowerCase();

        if (tempType === 'object' || tempType === 'array') {
            deepClone(temp);
        } else {
            target[i] = temp;   // 千万不要用push
        };
    };

    return target;
};


